// 获取ul元素

var oShopping = document.querySelector("#shopping");
(function(){
    var regExp = /(?<=imgurl=)[^'"]*/;
    var xhr = new XMLHttpRequest();

    xhr.open("get","http://chst.vip:1234/api/getmoneyctrl");
    xhr.send(null);
    xhr.onreadystatechange = function(){
        if(xhr.readyState === 4 && xhr.status === 200){
            var res = JSON.parse(xhr.responseText);
            console.log(res);
            console.log(res.result);
            var ele = "";
            res.result.forEach(item => {
                var img = regExp.exec(item.productImgSm);
                ele += `
                <li productid="${item.productId}" class="photo">
         <div class="photo_left"  productid="${item.productId}">
         <img src="${img}" alt=""  productid="${item.productId}">
     </div>
     <div class="photo_right"  productid="${item.productId}">
     <div class="photo_right_top"  productid="${item.productId}">
     <span  productid="${item.productId}">${item.productName}</span>
     <br>
     <span  productid="${item.productId}">${item.productPinkage}</span>
     </div>
     <div class="photo_right_bottom"  productid="${item.productId}">
         <span  productid="${item.productId}">${item.productFrom,item.productTime}</span>
         <span  productid="${item.productId}">
             <img src="../assets/images/消息.png" alt="">
             <p>${item.productComCount}</p>
         </span>
     </div>
     </li>     
                `
            });
        // 获取元素
        oShopping.innerHTML = ele;
           
        }
    }


// 点击事件
var shop= document.querySelector("#shopping")
shop.onclick = function(event){
    var e = event;
    console.log(e);
    var target = e.target;
    console.log(target);
    var id = target.getAttribute("productId");
    console.log(id);
    location.href="../html/省钱控详情.html?productid="+id
}

$(".gotop").click(function(){
    $("body,html").animate({scrollTop:0},1000)
})

})();
